package com.example.dragcontentviewdemo.activity.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.os.Build.VERSION_CODES;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

public class BubbleView extends View {

    private static final int COLOR_VALUE_ALPHA = 255;
    private static final int COLOR_VALUE_RED = 200;
    private static final float WIDTH_PROPORTION = 0.25f; //定义circle所占view的比例

    public BubbleView(Context context) {
        super(context);
    }

    public BubbleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
       // paint.setARGB(COLOR_VALUE_ALPHA,COLOR_VALUE_RED,0,0);
        paint.setColor(Color.RED);
        paint.setStyle(Style.FILL);
        paint.setStrokeWidth(8);
        paint.setShadowLayer(3,3,3,Color.BLACK);
        final float left = this.getLeft();
        final float right = this.getRight();
        final float top = this.getTop();
        final float bottom = this.getBottom();
        final float width = right - left;
        final float height = bottom - top;
        final float radius = WIDTH_PROPORTION * width;
        RectF rectOfCircle = new RectF(
                    width / 2 - radius / 2,
                    height / 2 - radius / 2,
                    width / 2 + radius / 2,
                    height / 2 + radius / 2
                );
        canvas.drawOval(rectOfCircle, paint);

    }
}
